package com.star.string;

/**
 * 用递归做累加
 */
public class RecursionAdd {

    public static void main(String[] args) {
//        System.out.println(normalAdd(100));
        System.out.println(recursionAdd(100));
    }

    public static int normalAdd(int n) {

        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }

    public static int recursionAdd(int n) {
        if (n == 1) {
            return 1;
        }
        return n + recursionAdd(n - 1);
    }
}
